package com.y.lintcode;

import java.util.Stack;

/**
 * @author Y2014188432
 * @date
 * 带最小值操作的栈
 */
public class Test12 {

    static Stack<Integer> stack = new Stack<>();
    static Stack<Integer> min = new Stack<>();


    public static void main(String[] args) {
        push(1);
        pop();
        push(2);
        push(3);
        min();
        push(1);
        min();
    }

    public static void push(int number) {
        pushMin(number);
        stack.push(number);
    }

    public static int pop() {
        min.pop();
        return stack.pop();
    }

    public static int min() {
        return min.peek();
    }

    public static void pushMin(int number){
        if (min.empty()){
            min.push(number);
        } else {
            int up = min.peek();
            int temp = Math.min(up,number);
            min.push(temp);
        }
    }

}
